package com.ymatou.iapi.im.testcase;

import com.ymatou.iapi.im.parameter.DeleteCSSessionByUserIdBean;
import com.ymatou.iapi.im.parameter.SendMessageBean;
import com.ymatou.iapi.im.service.DeleteCSSessionByUserIdCall;
import com.ymatou.iapi.userregister.parameter.UserRegisterInfoRequestDtoBean;
import com.ymatou.iapi.userregister.service.UserRegisterInfoRequestDtoCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymttest.business.service.ImCallService;
import com.ymttest.business.service.JUserCallService;
import com.ymttest.database.sqlwapper.ImDefaultWapper;
import com.ymttest.utils.EnvSetup;
import org.junit.*;
import org.junit.experimental.categories.Category;

import java.util.List;
import java.util.Map;

/**
*删除洋管家会话
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_DeleteCSSessionByUserId{
	private static DeleteCSSessionByUserIdBean deletecssessionbyuseridBean;
	private static DeleteCSSessionByUserIdCall deletecssessionbyuseridCall;
	private static int imId = Integer.parseInt(EnvSetup.getData("userId_IM"));
	private static String imName = EnvSetup.getData("userName_IM");
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("删除洋管家会话");
	}

	@Before
	public void caseUp() {
		deletecssessionbyuseridBean=new DeleteCSSessionByUserIdBean();
		deletecssessionbyuseridCall=new DeleteCSSessionByUserIdCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(deletecssessionbyuseridCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_DeleteCSSessionByUserId_01() {
		Logger.start(true,"删除洋管家会话");
		try {
			UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);
			Integer userId = urrc.getUserid();

			SendMessageBean sendMessageBean = ImCallService.initSendMessage(imId,userId,imName);
			ImCallService.SendMessage(sendMessageBean);

			deletecssessionbyuseridBean.setUserId(userId);
			deletecssessionbyuseridBean.setOtherUserId(imId);
			deletecssessionbyuseridCall.setData(deletecssessionbyuseridBean);
			deletecssessionbyuseridCall.callService();

			Logger.verifyEquals("Success",deletecssessionbyuseridCall.getString("Status"),"验证Status");
			ImDefaultWapper im = new ImDefaultWapper();
			List<Map> mapList = im.selectTotalCount(imId,userId);
			Logger.verifyEquals(true,mapList.isEmpty()?true:false,"验证session为空");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}